import { Body, Controller, Delete, Get, Post, Put } from '@nestjs/common';
import { Book } from './book.interface';
import { BookService } from './book.service';

@Controller('book')
export class BookController {
  constructor(private bookService: BookService) {
    this.bookService = bookService;
  }

  @Get('consultBook')
  async consultBook(): Promise<any> {
    return this.bookService.findAll();
  }

  @Post('findBook')
  async findBook(@Body('name') name: string): Promise<any> {
    if (!name) {
      return this.bookService.findAll();
    }
    return this.bookService.findBook(name);
  }

  @Post('addBooks')
  async addBooks(@Body() params: Book | Book[]): Promise<any> {
    return this.bookService.addBook(params);
  }

  @Delete('deleteBook')
  async deleteBook(@Body('ids') ids: string[]): Promise<any> {
    return this.bookService.deleteBook(ids);
  }

  @Put('updateBook')
  async updateBook(
    @Body('ids') ids: string[],
    @Body('bookData') bookData: Book,
  ): Promise<any> {
    return this.bookService.updateBook(ids, bookData);
  }

  @Get('demoAxios')
  async demoAxios() {
    return this.bookService.demoAxios();
  }
}
